﻿using System;
using System.Collections.Generic;
using System.Linq;

using SharedGenomics.Core;
using SharedGenomics.Annotations;

namespace SharedGenomics.Workbench.Presenters
{
    public class AnnotationMenuProviderRegistry
    {
        private ICollection<IAnnotationMenuProvider> _providers;

        public AnnotationMenuProviderRegistry()
        {
            this._providers = new List<IAnnotationMenuProvider>();
        }

        public void RegisterProvider(IAnnotationMenuProvider menuProvider)
        {
            menuProvider.ThrowIfNull("menuProvider");

            //TODO: throw exception if provider is already registered...?
            this._providers.Add(menuProvider);
        }

        public IEnumerable<IAnnotationMenuProvider> GetMenuProvidersForAnnotation(IAnnotation annotation)
        {
            annotation.ThrowIfNull("annotation");

            Type annotationType = annotation.GetType();
            return this._providers.Where(p => p.AnnotationType.IsAssignableFrom(annotationType));
        }
    }
}
